import Vue from 'vue'
import Vuex from 'vuex'
import mTypes from './mutationsTypes'
import createPersistedState from "vuex-persistedstate"

Vue.use(Vuex)
const createStorage = createPersistedState({
  key: 'vuexStorage',
  storage: window.localStorage,
})

export default new Vuex.Store({
  state: {
    loginModalVisible: false,
    forgetModalVisible: {visible: false},
    access_token: '',
    userInfo: {}
  },
  mutations: {
    // 设置登录信息
    [mTypes.setLoginInfo](state, info) {
      state.access_token = info
    },
    [mTypes.userInfo](state, info) {
      state.userInfo = info
    },
    [mTypes.logout](state, info) {
      state.userInfo = {},
      state.access_token = ''
    },
    [mTypes.loginModal](state, visible) {
      state.loginModalVisible = visible;
    },
    [mTypes.forgetModal](state, info) {
      state.forgetModalVisible = info
    }
  },
  actions: {},
  modules: {},
  plugins: [createStorage]
})
